<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .div1 {
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
    <script>
        window.onload = function() {
            var div1 = document.querySelector('.div1'); // 获取类名为div1的元素
            div1.onclick=function(){
                div1.style.backgroundColor = 'blue'; // 修改背景颜色为蓝色
            }
            var btn1=document.querySelector('.btn1'); // 获取类名为btn1的元素
            btn1.onclick = function() {
                div1.style.backgroundColor = 'green'; // 修改背景颜色为绿色
            };
        };
    </script>
</head>
<body>
    <div class="div1"></div>
    <button class="btn1">按钮</button>
</body>
</html>